package spark.core.scala

import org.apache.spark.{SparkContext, SparkConf}

/**
 * 二次排序
 */
object SecondSort {


  def main(args: Array[String]) {
    val conf = new SparkConf()
      .setAppName("SortWordCount")
      .setMaster("local")
    val sc = new SparkContext(conf)
    val lines = sc.textFile("datas/secondSort.txt",1)

    val pairs = lines.map(line => {
      (new SecondarySort(line.split(" ")(0).toInt,line.split(" ")(1).toInt),line)
    } )
    val sortedPairs = pairs.sortByKey()
    val sortedLines = sortedPairs.map(sortedpair => sortedpair._2)
    sortedLines.foreach(sortedLine => println(sortedLine))
  }
}
